package com.gliese.renren;

import java.util.HashSet;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gliese.renren.util.RenrenPropertiesUtil;

public class GoToProfilePageTimer {
	private final static Log log = LogFactory
			.getLog(GoToProfilePageTimer.class);

	public static void main(String[] args) throws Exception {
		WebClient wc = new WebClient();
		RenrenApp.loginToRenRen(wc);
		HashSet<String> toViewIds = RenrenPropertiesUtil.getToViewIds();
		try {
			for (int iter = 0; iter < 20; iter++) {
				Iterator<String> iterator = toViewIds.iterator();
				if (!iterator.hasNext())
					break;
				String id = iterator.next();
				HtmlPage profilePage = RenrenApp.toFriendProfilePage(wc, id);
				System.out.println(id + " : " + profilePage.getTitleText());
				RenrenApp.findOnlineOrLivelyUserFriendProfiles(profilePage);

			}
		} catch (RuntimeException re) {
			
			if (log.isErrorEnabled())
				log.error("runtimeException occurs for some reason !");
				log.error(re.getStackTrace());
		}
		RenrenPropertiesUtil.storeHasViewProfileIds();
		RenrenPropertiesUtil.storeToViewProfileIds();
		wc.closeAllWindows();
		System.exit(0);
	}
}
